/*
BMP.hpp
By math4tots

I'm using http://paulbourke.net/dataformats/bmp/ as reference to the bmp structure

header
info header
optional palette
image data

*/

#ifndef BMP_HPP
#define BMP_HPP
#include<fstream>
#include<string.h>
#include"ByteArray.hpp"
namespace std{

class BMP{
public:
	explicit BMP(const char* filename);
	BMP(ByteArray ba);
	BMP& operator=(BMP other);
	
	//Input/Output
	void save(const char* filename);
	void load(const char* filename);
	
	//Capacity
	unsigned long size();
	
	//Header/Information
	char* info(const char* field);
private:
	ByteArray data;
	static const char* infoDom[];
	static const int   infoRan[];
};
const char* BMP::infoDom[] =
{
//Header stuff
"htype",
"hsize",
"hreserved1",
"hreserved2",
"hoffset",
//Information stuff
"isize",
"iwidth",
"iheight",
"iplanes",
"ibits",
"icompression",
"iimagesize",
"ixresolution",
"iyresolution",
"incolours",
"iimportantcolours",
};
const int   BMP::infoRan[] =
{
//Header stuff
0,
2,
6,
8,
10,
14,
//Information stuff
18,
22,
26,
28,
30,
34,
38,
42,
46,
50,
54,
};


BMP::BMP(const char* filename){data.load(filename);}
BMP::BMP(ByteArray ba){data = ba;}
//BMP& BMP::operator=(BMP other){data = other.data; return *this;}
void BMP::save(const char* filename){data.save(filename);}
void BMP::load(const char* filename){data.load(filename);}
unsigned long BMP::size(){ return data.size(); }
char* BMP::info(const char* field){
	for (int i = 0; i < sizeof(infoRan) / sizeof(int); i++){
		if (strcmp(field, infoDom[i]) == 0)  return data(infoRan[i]);
	}
	return NULL;
}

}


#endif//BMP_HPP
